/**
 * Convert a specially formed object into an XML string
 * 
 * @author: John Manero
 */
Object.prototype.toXML = function() {
	if(typeof(this) == 'string') { // I'm a string
		return this;
	} else if(Array.isArray(this)) { // I'm an array
		var contents = "";
		
		for(var i=0; i < this.length; i++) {
			contents += this[i].toXML();
		}
		
		return contents;
	} else if(typeof(this) == 'function'){ // I'm a function. Don't do anything.
		return "";
	} else { // I'm an object
		var _class = this.__XMLclass || 'object';
		
		var children = [];
		if(Array.isArray(this.__XMLchildren)) {
			children = this.__XMLchildren;
		} else if(typeof(this.__XMLchildren) != 'undefined') {
			children.push(this.__XMLchildren);
		}
		
		// Make header
		var xml = "<" + _class;
		for(var key in this) {
			if(typeof(this[key]) == 'function') // No Functions!
				continue;
			
			if(key == '__XMLclass') // Ignore the class designator
				continue;
			
			if(key == '__XMLchildren') // Ignore the children designator
				continue;
			
			xml += " " + key + "=\"" + this[key] + "\"";
		}
		
		if(children.length > 0) {
			xml += ">"; // Close Header
			xml += children.toXML(); // Add Child(ren)
			xml += "</" + _class + ">"; // Add trailer
		} else {
			xml += "/>"; // Close Header
		}
		
		return xml;
	}
};

Object.prototype.setXMLClass = function(name) {
	this.__XMLclass = name;
};

Object.prototype.getXMLClass = function() {
	return this.__XMLclass || 'Object';
};

Object.prototype.getXMLChildren = function(index) {
	if(typeof(index) == 'number') {
		if(Array.isArray(this.__XMLchildren)) {
			return this.__XMLchildren[index] || {};
		} else {
			return this.__XMLchildren || {};
		}
	} else {
		return this.__XMLchildren || [];
	}
};
